package com.zx.web;


import com.zx.Utils.StringUtils;
import com.zx.domain.Result;
import com.zx.service.UserService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
@RequestMapping(value="/admin")
public class Login {
	protected static Logger logger= LogManager.getLogger(Login.class);
	@Autowired
	UserService userService;
	@ResponseBody
	@RequestMapping(value="/login.zx",method= RequestMethod.GET)
	public Result login( String name,String pwd,HttpServletRequest request){
		logger.info("Login.login入参:"+request.getQueryString());
		if(!StringUtils.isChecks(name))
		{
			return new Result("用户名不能为空","-1",null);
		}
		if(!StringUtils.isChecks(pwd))
		{
			return new Result("密码不能为空","-1",null);
		}
		Map<?,?> user=userService.login(name,pwd);
		if(user==null){
			return new Result("登陆用户名或密码错误","-1",null);
		}
		else
		{
			HttpSession session = request.getSession();
			session.setAttribute("id", user.get("id"));
			return new Result("登录成功","0",null);
		}
		
	}
}
